<%@ page language="java" contentType="text/html; charset=UTF-8" import="com.jd.po.User"
    pageEncoding="UTF-8"%>
<%String path= "http://"+request.getHeader("host")+request.getContextPath(); %>
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>抽包向导页面</title>
<script src="../js/jQuery.js" type="text/javascript"></script>
<script type="text/javascript">
</script>
<link href="../skin/2011/base.extraction.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<script src="/js/jquery-1.2.6.min.js" type="text/javascript"></script>
<script>
//为了避免 jquery中的'$'与其它的'$'冲突,在此将jquery中的'$'重命名为'jQuery'
var jQuery=$;

$.ajaxSetup ({cache:false});
//初始化数据
//jQuery(document).ready(function(){getTrunkOrBranch();});
//取所有TrunkOrBranch
//function getTrunkOrBranch(){
	//&callback=?"注意这个是为了解决跨域访问 的问题   
//	var url ="http://www.yimei.com/shopcar/getAreaJSON?areaId=0&callback=?";
//	jQuery.getJSON(url,null,function call(result){
//		setTrunkOrBranch(result); 
//	});
//}
//设置TrunkOrBranch
//function setTrunkOrBranch(result){
//	var trunkOrBranch = document.getElementById("toTrunkOrBranch");
//	jQuery.each(result.data, function(i, area){
//		var value = area.id;
//		var text = area.name;
//		var option = new Option(text,value);
//		trunkOrBranch.options.add(option);
//	}); 
//}
//按上级ID取项目
function getArea(name){
	if( name=='toProject' ){
		clearSel(document.getElementById("toProject"));
		 //清空项目
		var trunkOrBranch = document.getElementById("toTrunkOrBranch");
		var areaId = trunkOrBranch.value;
		var url ="<%=path %>"+"/getProjectListAction.action?areaId="+areaId;
	    jQuery.ajax({
	        	url: url,
	       		dataType: 'text',
	        	success: function(result) {
	    			var arr = eval(result);
	    			setProject(arr);
	        	}
	    });
	}
}
function setForm() {
	var toProject = document.getElementById("toProject");
	if(toProject.options[toProject.selectedIndex].value == "") return;
	var projectName = toProject.options[toProject.selectedIndex].value;
	$("#url").val(projectName);
	whichDomain();
	$('#treeForm').submit();
}
function setProject(result){
	var project = document.getElementById("toProject");
	jQuery.each(result, function(i, area){
		var value = area;
		var text = area;
		var option = new Option(text,value);
		project.options.add(option);
	});
	
}
// 清空下拉列表
function clearSel(oSelect){
	while(oSelect.childNodes.length>0){
		oSelect.removeChild(oSelect.childNodes[0]);
	}
}

//设置主干分支初始值
function setTB(result){
	var toTrunkOrBranch = document.getElementById("toTrunkOrBranch");
	clearSel(toTrunkOrBranch);
	if(result=='Test') {
		var option1 = new Option('主干','t');
		toTrunkOrBranch.options.add(option1);
		var option2 = new Option('分支','b');
		toTrunkOrBranch.options.add(option2);
	}else if(result=='OwnTest') {
		var option1 = new Option('主干','t');
		toTrunkOrBranch.options.add(option1);
	}
	getArea('toProject');
}
//辨别是哪个域名
function whichDomain() {
	var domainSelect = $('#domainSelect option:selected').val();
	if(domainSelect=='1') {
		$('#domainName').val("I_"+$('#domain1').val());
	}
	if(domainSelect=='2') {
		$('#domainName').val("I_"+$('#domain2-1').val()+"_"+$('#domain2-2').val());
	}
	if(domainSelect=='3') {
		$('#domainName').val("W_"+$('#domain3').val());
	}
}
</script>
<div class="w">
	<form action="../fileTree/Tree.jsp" method="post" id="treeForm">
		<div class="m list">
			<div class="mt">
				<h2>抽包向导页面</h2>
				<div class="extra">
					<label>欢迎您:<span><%=((User)session.getAttribute("user")).getCnName()%></span></label>
					<a href="../logout.action">退出</a>
				</div>
			</div>
			<div class="mc">
				<dl>
					<dt>
						<h3 style="font-family:verdana">1.请选择上线类型</h3>
					</dt>
					<dd>
						<input type="radio" value="ZhengChang" name="onLineType" id="normal">
						正常上线
						<input type="radio" value="OnlineChange" name="onLineType" id="change">
						线上修改 </dd>
					<dt>
						<h3 style="font-family:verdana">2.请选择项目测试类型</h3>
					</dt>
					<dd>
					<input type="radio" id="test" name="testType" disabled="disabled" value="Test" />测试组测试项目
					<%if(request.getParameter("tOrb").equals("t")) {%>
					<input type="radio" id="dev" name="testType" disabled="disabled" value="OwnTest" />开发组自测项目
					<%} %>
					</dd>
					<dt>
						<h3 style="font-family:verdana">3.选择要抽包的项目</h3>
					</dt>
					<dd>
						<select class="board" id="toProject" name="toProject">
							<option selected="selected" value="">请先选择项目测试类型...</option>
						</select>
					</dd>
					<dt>
						<h3 style="font-family:verdana">4.请选择域名类型，并填入相应空白处。</h3>
					</dt>
					<dd>
						<select class="board" id="domainSelect" name="domainSelect">
							<option selected value="1">站点</option>
							<option value="2">虚拟目录</option>
							<option value="3">worker</option>
						</select>
						<div style="display: block" id="domainDiv1"> I_
							<input type="text" value="" name="domainName1" id="domain1">
							<br>
						</div>
						<div style="display: none" id="domainDiv2"> I_
							<input type="text" value="" disabled="disabled" name="domainName2" id="domain2-1">
							_
							<input type="text" value="" disabled="disabled" name="domainName2" id="domain2-2">
							<br>
						</div>
						<div style="display: none" id="domainDiv3"> W_
							<input type="text" value="" disabled="disabled" name="domainName3" id="domain3">
							<br>
						</div>
						<input type="hidden" value="<%=request.getParameter("tOrb") %>" id="toTrunkOrBranch" name="tOrb">
						<input type="hidden" value="" name="projectName" id="url">
						<input type="hidden" value="" name="domainName" id="domainName">
						<input type="button" value="确认" name="done">
					</dd>
				</dl>
			</div>
			<div class="mb">
				Copyright 2004-2011  360buy京东商城 版权所有
			</div>
		</div>
	</form>
</div>
</body>
<script>
$(function(){
	$('#domainSelect').change( function() {
			if($(this).val()=='1') {
				$('#domainDiv1').css("display","block"); 
				$('#domainDiv2').css("display","none"); 
				$('#domainDiv3').css("display","none"); 
				$('#domain2-1').attr("disabled","disabled");
				$('#domain2-2').attr("disabled","disabled");
				$('#domain3').attr("disabled","disabled");
				$('#domain2-1').val("");
				$('#domain2-2').val("");
				$('#domain3').val("");
				$('#domain1').removeAttr("disabled");
			}
			if($(this).val()=='2') {
				$('#domainDiv1').css("display","none"); 
				$('#domainDiv2').css("display","block"); 
				$('#domainDiv3').css("display","none"); 
				$('#domain2-1').removeAttr("disabled");
				$('#domain2-2').removeAttr("disabled");
				$('#domain3').attr("disabled","disabled");
				$('#domain1').attr("disabled","disabled");
				$('#domain1').val("");
				$('#domain3').val("");
			}
			if($(this).val()=='3') {
				$('#domainDiv1').css("display","none"); 
				$('#domainDiv2').css("display","none"); 
				$('#domainDiv3').css("display","block"); 
				$('#domain2-1').attr("disabled","disabled");
				$('#domain2-2').attr("disabled","disabled");
				$('#domain3').removeAttr("disabled");
				$('#domain1').attr("disabled","disabled");
				$('#domain2-1').val("");
				$('#domain2-2').val("");
				$('#domain1').val("");
			}
	});
	$("input[name=onLineType]").change( function() {
		jQuery.each($("input[name=testType]"), function(i, testType){
			testType.disabled=false;
		});
	});
	$("input[name=testType]").change( function() {
		getArea('toProject');
	});
	$("input[name=done]").click( function() {
		if((($('#domain2-1').val()!=null&&$('#domain2-1').val()!="")&&($('#domain2-2').val()!=null&&$('#domain2-2').val()!=""))||($('#domain1').val()!=null&&$('#domain1').val()!="")||($('#domain3').val()!=null&&$('#domain3').val()!="")) {
			setForm();
		}else {
			alert("请填入域名！");
		}
		
	});
});
	
</script>
</html>